﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.IO;
using System.Drawing;

namespace RAMED
{
    class utitlitaire
    {

        public static int CasterString(string str )
        {
            try
            {
                
                    return int.Parse(str);

            }
            catch (Exception ex)
            {
                
                return 0;
            }
        }


        public static bool EqualsSansCasse(string str1, string str2)
        {
            return str1.ToUpper().Equals(str2.ToUpper());
        }

        public static void ValiderNombre( string messageErreur, TextBox textBoxAValider, CancelEventArgs e, ErrorProvider errorProvider)
        {
            int number = -1;
            if (!int.TryParse(textBoxAValider.Text, out number))
            {
                e.Cancel = true;
                errorProvider.SetError(textBoxAValider, messageErreur);
            }
        }

        internal static byte[] ConvertirImageABinary(System.Drawing.Image image)
        {
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return ms.ToArray();

        }

        

        internal static Image ConvertirBinaryAImage(byte[] p)
        {
            MemoryStream ms = new MemoryStream(p);
            return Image.FromStream(ms);
        }

        internal static void ValiderChampsRecquit(string messageErreur, TextBox textBox, CancelEventArgs e, ErrorProvider errorProvider)
        {
            if (textBox.Text.Equals(""))
            {
                e.Cancel = true;
                errorProvider.SetError(textBox, messageErreur);
            }
        }

        internal static void ValiderChampsRecquit(string messageErreur, TextBox textBox, EventArgs e, ErrorProvider errorProvider)
        {
            if (textBox.Text.Equals(""))
            {
                //e.Cancel = true;
                errorProvider.SetError(textBox, messageErreur);
            }
        }
    }
}
